package net.zdreamer.shunyi.ui.fragment;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import net.zdreamer.shunyi.R;
import net.zdreamer.shunyi.adapter.MessageListAdapter;
import net.zdreamer.shunyi.adapter.PaiHangAdapter;
import net.zdreamer.shunyi.myview.XListView;
import net.zdreamer.shunyi.utils.ListUtils.PaiHangInfos;


public class BanghuiPaihangFragment extends Fragment implements XListView.IXListViewListener {
    private XListView paihanglist;
    private PaiHangAdapter mAdapter;
    private Handler mHandler;
    private int start = 0;
    private static int refreshCnt = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_banghui_paihang, container, false);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

    }

    @Override
    public void onStart() {
        super.onStart();
        paihanglist = (XListView) getView().findViewById(R.id.paihanglist);

        PaiHangInfos paiHangInfos = new PaiHangInfos();
        mAdapter = new PaiHangAdapter(getActivity(), paiHangInfos.paihanginfos, R.layout.paihanglist_item);
        paihanglist.setAdapter(mAdapter);
        paihanglist.setXListViewListener(this);
        paihanglist.setPullLoadEnable(true);
        mHandler = new Handler();
    }

    private void onLoad() {
        paihanglist.stopRefresh();
        paihanglist.stopLoadMore();
        paihanglist.setRefreshTime("刚刚");
    }

    @Override
    public void onRefresh() {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                start = ++refreshCnt;
                onLoad();
            }
        }, 500);
    }

    @Override
    public void onLoadMore() {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                onLoad();
            }
        }, 2000);
    }
}
